﻿using System;
using System.Collections.ObjectModel;
using AvaloniaWeChatList.Controls;
using AvaloniaWeChatList.Models;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;

namespace AvaloniaWeChatList.ViewModels;

public partial class MainViewModel : ViewModelBase
{
    [ObservableProperty] private ObservableCollection<ChatItemModel> _chats;

    [ObservableProperty] private object? _currentPage;

    public MainViewModel()
    {
        Chats = new ObservableCollection<ChatItemModel>
        {
            new ChatItemModel
            {
                ChatType = ChatType.Group,
                ChatPage = new ChatContent("WeChat9d4a4944153e55d0c0c0d7bf9fbcfc62.jpg"),
                Photo = BitmapUntil.Load("1ca35eb545be21611f9b414999cdefac.jpg"),
                Name = "SuperSocket开...",
                Content = "我擦：.我擦.net 8 L",
            },
            new ChatItemModel
            {
                ChatPage = new ChatContent("WeChatab19504e7b125c8ce56200747499d94a.jpg"),
                Photo = BitmapUntil.Load("1ca35eb545be21611f9b414999cdefac.jpg"),
                Name = "红糖",
                Content = "我试试",
            },
            new ChatItemModel
            {
                ChatPage = new ChatContent("WeChatab19504e7b125c8ce56200747499d94a.jpg"),
                Photo = BitmapUntil.Load("02a4881842b524506799e985420ef4a3.jpg"),
                Name = "西瓜",
                Content = "你上周做的怎么样？",
            },
            new ChatItemModel
            {
                ChatPage = new ChatContent("WeChatab19504e7b125c8ce56200747499d94a.jpg"),
                Photo = BitmapUntil.Load("3094e5857c5be26f4e6b78e4e36bcaa0.jpg"),
                Name = "小雪",
                Content = "没什么",
            },
            new ChatItemModel
            {
                ChatPage = new ChatContent("WeChatab19504e7b125c8ce56200747499d94a.jpg"),
                Photo = BitmapUntil.Load("a27b04e19fe062e0f64e9319f98d590a.jpg"),
                Name = "彩虹",
                Content = "测试一下？",
            },
            new ChatItemModel
            {
                ChatType = ChatType.App,
                ChatPage = new ChatContent("WeChatbab958e8fb848537cf7888732a89d228.jpg"),
                Photo = BitmapUntil.Load("4dd2d5b3cbf981fdfd37581fc0d948af.jpeg"),
                Name = "腾讯新闻",
                Content = "[链接]时政微观察｜以中...",
                IsDisturb = false,
            },
            new ChatItemModel
            {
                ChatType = ChatType.Group,
                ChatPage = new ChatContent("WeChatab19504e7b125c8ce56200747499d94a.jpg"),
                Photo = BitmapUntil.Load("1ca35eb545be21611f9b414999cdefac.jpg"),
                Name = "SuperSocket开...",
                Content = "我擦：.我擦.net 8 L",
            },
            new ChatItemModel
            {
                ChatPage = new ChatContent("WeChatab19504e7b125c8ce56200747499d94a.jpg"),
                Photo = BitmapUntil.Load("1ca35eb545be21611f9b414999cdefac.jpg"),
                Name = "红糖",
                Content = "我试试",
            },
            new ChatItemModel
            {
                ChatPage = new ChatContent("WeChatab19504e7b125c8ce56200747499d94a.jpg"),
                Photo = BitmapUntil.Load("02a4881842b524506799e985420ef4a3.jpg"),
                Name = "西瓜",
                Content = "你上周做的怎么样？",
            },
            new ChatItemModel
            {
                ChatPage = new ChatContent("WeChatab19504e7b125c8ce56200747499d94a.jpg"),
                Photo = BitmapUntil.Load("3094e5857c5be26f4e6b78e4e36bcaa0.jpg"),
                Name = "小雪",
                Content = "没什么",
            },
            new ChatItemModel
            {
                ChatPage = new ChatContent("WeChatab19504e7b125c8ce56200747499d94a.jpg"),
                Photo = BitmapUntil.Load("a27b04e19fe062e0f64e9319f98d590a.jpg"),
                Name = "彩虹",
                Content = "测试一下？",
            },
            new ChatItemModel
            {
                ChatType = ChatType.App,
                ChatPage = new ChatContent("WeChatab19504e7b125c8ce56200747499d94a.jpg"),
                Photo = BitmapUntil.Load("4dd2d5b3cbf981fdfd37581fc0d948af.jpeg"),
                Name = "腾讯新闻",
                Content = "[链接]时政微观察｜以中...",
                IsDisturb = false,
            },
        };
    }

    [RelayCommand]
    private void OnSelected(ChatItemModel? item)
    {
        if (item?.ChatPage == null)
            return;
     
        CurrentPage = item.ChatPage;
        item.ChatPage.Model.ChatItemModel = item;
        item.ChatPage.Model.Enter();
    }
}